package com.jp.knowledge.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.NonNull;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.my.model.HelpCateModel;
import com.jp.knowledge.util.ImageLoadUtil;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/8/2.
 */

public class FirstLoginGridAdapter extends RecycleVAdapter<HelpCateModel> {

	public FirstLoginGridAdapter(Context context, @NonNull List<HelpCateModel> list) {
		super(context, list);
	}

	@Override
	public int getLayoutId(int viewType) {
		return R.layout.item_first_login_grid;
	}

	@Override
	public void onBind(RecycleVHolder holder, int position) {
		HelpCateModel data = getData(position);
		TextView title = holder.getTextView(R.id.title);
		title.setText(data.getTitle());
		int color;
		try {
			color = Color.parseColor(data.getColor());
		} catch (Exception e){
			color = mContext.getResources().getColor(R.color.font_black_think);
		}
		title.setTextColor(color);
		ImageView icon = holder.getImageView(R.id.icon);
		ImageLoadUtil.load(mContext, data.getIcon(), icon);
		GradientDrawable gd = new GradientDrawable();
		gd.setColor(color);
		gd.setCornerRadius(10);
		icon.setBackground(gd);
	}
}
